<#include "/common/layout.html">
<@body>
<div class="content">
	<form method="post" class="form-horizontal"
		action="${request.contextPath}/system/menu/doEdit" id="editActionForm">
		<input type="hidden" name="menuId" value="${(sysMenu.menuId)!}" />
		<div class="box-body">
			<div class="form-group">
				<label class="col-sm-2 control-label">父级目录</label>
				<div class="col-sm-10">
					<select id="dir" class="form-control select2" style="width: 100%;" data-placeholder="--请选择父级目录--" required>
						<option></option>
						<#list list as m>
						<option value="${(m.menuId)!}" ${(m.menuId==pSysMenu.pid)?string('selected="selected"','')}>${(m.code)!}-${(m.menuName)!}</option>
						</#list>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">上级菜单</label>
				<div class="col-sm-10">
					<select id="pid" name="pid" class="form-control select2" style="width: 100%;" data-placeholder="--请选择上级菜单--" required>
						<option></option>
						<option value="${(pSysMenu.menuId)!}" selected="selected">${(pSysMenu.code)!}-${(pSysMenu.menuName)!}</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">编码</label>
				<div class="col-sm-10">
					<input type="text" name="code" class="form-control" value="${(sysMenu.code)!}" placeholder="请输入编码,如050101" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">功能名称</label>
				<div class="col-sm-10">
					<input type="text" name="menuName" value="${(sysMenu.menuName)!}" class="form-control" placeholder="请输入目录名称" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">权限资源</label>
				<div class="col-sm-10">
					<input type="text" id="resource" name="resource" value="${(sysMenu.resource)!}" class="form-control" placeholder="请输入权限资源名称" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序</label>
				<div class="col-sm-10">
					<input type="text" name="sort" value="${(sysMenu.sort)!}" class="form-control" placeholder="请输入排序" required>
				</div>
			</div>
		</div>
	</form>
</div>
</@body> <script type="text/javascript">
	$("#dir").on('change', function() {
		var pid = $(this).val();
		$.post('${request.contextPath}/system/menu/json?_dc=' + new Date().getTime(), {
			pid : pid
		}, function(response) {
			if (response.code == 200) {
				$("#pid").empty();
				var initOption = {"id": -1,"text": "--请选择上级菜单--"};
				response.data.unshift(initOption)
				$("#pid").select2({
					data : response.data
				});
			}
		});
	});
	function submitHandler() {
		if ($("#editActionForm").validate().form()) {
			var formData = $("#editActionForm").serialize();
			var index = layer.load(3); // 换了种风格
			$.ajax({
				url : $("#editActionForm").attr('action'),
				type : 'POST',
				dataType : "json",
				data : formData,
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					layer.close(index);
					if (data.code == 200) {
						if (data.msg) {
							parent.layer.msg(data.msg, {
								icon : 1
							});
						} else {
							parent.layer.msg('提交成功', {
								icon : 1
							});
						}
						parent.layer.closeAll('iframe'); // 关闭当前frame
						window.parent.dataTable.draw(false);
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		}
	}
</script>